/*
*Script by Icecoldcoke - Some help from T0astinat0rz
*http://ice-scripting.googlecode.com/svn/trunk/
*Icecoldcoke Gossip Menu - ID 690003 
*/

#include "StdAfx.h"
#include "Setup.h"

#ifdef WIN32
#pragma warning(disable:4305) // This will disable the warning message that happens on compiling..
#endif

class SCRIPT_DECL Icecoldcoke : public GossipScript
{
	public:
		void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
		void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
		void GossipEnd(Object * pObject, Player* Plr);
		void Destroy()
	{
		delete this;
	}
};

void Icecoldcoke::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
    GossipMenu *Menu;
		uint32 TextID = 820;

		objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), TextID, Plr);
		Menu->AddItem(0, "So... thirsty...", 1);			         // This is the milk menu
		Menu->AddItem(0, "Teleport Menu", 2);						// Teleport menu (20+)
		Menu->AddItem(0, "GM Menu (Req. Lvl 255)", 16);			   // GM Menu ... all can see.. 255 required to enter.
		Menu->AddItem(10, "Please Morph me Back to Normal!", 15); // Demorphs the player to prevent being stuck as a cow
	    Menu->AddItem(10, "Please fix my gold, Icecoldcoke", 23); // If player has more than 200k gold, it will set thier gold to 150k (That way if they kill something and get gold it wont get bugged right after)
    if(AutoSend)
        Menu->SendTo(Plr);
}

void Icecoldcoke::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
{
	Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NULL;
	if(pCreature==NULL)
		return;

		GossipMenu *Menu;

		switch(IntId)
		{

			case 0: 
				{
					GossipHello(pCreature, Plr, true);
				}
				break;


			case 1: //This is the milk menu 
				{
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(5, "Cow Morph - 1 Milks", 3); // This morphs into a cow at the cost of 1 milk
						Menu->AddItem(5, "Fortitude - 2 Milks", 4); // Casts fort at the cost of 1 milk
					if(Plr->getLevel() >= 70)
					{
						Menu->AddItem(5, "MOTW - 3 Milks)", 5); // This will display ONLY if the target is above level 70 or equal to level 70.. for 3 milks they can get MOTW
					}
						Menu->AddItem(0, "[Back]", 99); // This will display the main menu
						Menu->SendTo(Plr);
				}
				break;





			case 2://Teleport Menu
				{
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
					if(Plr->getLevel() >= 20) // This checks if the person talking is level 20 or higher, if they are, then these menu items are displayed
					{
						Menu->AddItem(0, "Stormwind", 6); // This ports to SW
						Menu->AddItem(0, "Ironforge", 7); // Ports to IF
						Menu->AddItem(0, "Exodar", 8); // Ports to exodar
						Menu->AddItem(0, "Darnassus", 9); // Ports to darn
						Menu->AddItem(0, "Orgrimar", 10); // Ports to org
						Menu->AddItem(0, "Thunder Bluff", 11); // Ports to TB
						Menu->AddItem(0, "Silvermoon City", 12); // Ports to SMC
						Menu->AddItem(0, "Undercity", 13); // Ports to UC
						Menu->AddItem(0, "Shattrath", 14); // ports to shatt
						Menu->AddItem(0, "[Back]", 99); // Goes back to the main menu
						Menu->SendTo(Plr);
					}
					else
					{
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Sorry, you must reach level 20 to access the teleport menu."); // If they target is not level 20, or higher, it will display this message in say.
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 99); // Back to main menu
						Menu->SendTo(Plr);	
					}
				break;

			case 3://Morph into Cow Model :1060
				{
					if(Plr->GetItemInterface()->GetItemCount(1179, false) >=1) // Checks if milk count is greater than or equal to 1
					{
						Plr->GetItemInterface()->RemoveItemAmt(1179, 1);  //removes 1 Milk     
						Plr->SetUInt32Value(UNIT_FIELD_DISPLAYID, 1060); //morphs into cow
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Mooooooooo....!!!");
					}
					else
					{
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Soo...thirsty... need..more...Milks");//dont have enough Milks for this.. so error in say is displayed
					}
           
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 1); // This will go back to the milk menu, since that is where they were at!
						Menu->SendTo(Plr);
				}
				break;

			case 4://Fortitude
				{
					if(Plr->GetItemInterface()->GetItemCount(1179, false) >=2) // Checks if milk count is greater than or equal to 2
					{
						Plr->GetItemInterface()->RemoveItemAmt(1179, 2);//removes 2 milks
						pCreature->CastSpell(Plr,10938,0);//buffs with fortitude
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "You shouldn't die so easily now! :D");
					}
					else
					{
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Soo...thirsty... need..more...Milks"); //dont have enough Milks for this..
					}
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 1); // Goes back to milk menu
						Menu->SendTo(Plr);
				}
				break;

			case 5://Level 70 MOTW Buff
				{
					if(Plr->GetItemInterface()->GetItemCount(1179, false)>=3)  // Checks if milk count is greater than or equal to 3
					{
						Plr->GetItemInterface()->RemoveItemAmt(1179, 3);//removes 3 Milks
						pCreature->CastSpell(Plr,26990,0);//buffs with MOTW
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "You feel.. more wild.");
					}
					else
					{
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Soo...thirsty... need..more...Milks");//dont have enough Icecoldcokes for this
					}
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 1);
						Menu->SendTo(Plr);
				}
				break;

			case 6:// Ports ToStormwind
				{
					Plr->SafeTeleport(0, 0, -8913.23, 554.633, 93.7944, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 7://Ports To Ironforge
				{
					Plr->SafeTeleport(0, 0, -4981.25, -881.542, 501.66, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 8://Ports To Exodar
				{
					Plr->SafeTeleport(530, 0, -3987.29, -11846.6, -2.01903, 0);
					Plr->Gossip_Complete();
			   }
			   break;
                    
			case 9://Ports To Darnassus
				{
					Plr->SafeTeleport(1, 0, 9951.52, 2280.32, 1341.39, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 10://Ports To Orgrimmar
				{
					Plr->SafeTeleport(1, 0, 1499.55, -4406.91, 23.1642, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 11://Ports To Thunder Bluff
				{
					Plr->SafeTeleport(1, 0, -1195.88, -56.5582, 160.034, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 12://Ports To Silvermoon City
				{
					Plr->SafeTeleport(530, 0, 9473.03, -7279.67, 14.2285, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 13://Ports to UC
				{
					Plr->SafeTeleport(0, 0, 1615.1, 239.786, -62.0774, 0);
					Plr->Gossip_Complete();
				}
				break;
                    
			case 14://Ports to Shattrath
				{
					if(Plr->getLevel() >= 58) // Checks if the player's level is greater than, or equal to 58..
					{
						Plr->SafeTeleport(530, 0, -1863.03, 4998.05, -21.1847, 0);
						Plr->Gossip_Complete();
					}
					else
					{//Not level 58 so tells them they need to be level 58
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Sorry, you must reach 58 to enter Outlands");
						objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 2); // Goes back to the teleport menu, since that is where they were!
						Menu->SendTo(Plr);			
				}
				break;

			case 15: // Demorphs and sends a message
				{
					pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Awww.. was fun while it lasted!");
					Plr->DeMorph();
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 99); // Goes to the main menu
						Menu->SendTo(Plr);  
				}
				break;

			case 16: //GM Menu :D
				{
					if(Plr->getLevel () >= 255)
					{
						objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "Cool Spells", 17); // Menu with spells to learn
						Menu->AddItem(0, "Cool Locations", 18); // Menu with port locations
						Menu->AddItem(0, "GM Sets", 19); // Menu where they can get the GM set
						Menu->AddItem(0, "[Back]", 99); // Goes to the main menu
						Menu->SendTo(Plr);
					}else{ 
						pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Sorry, you must reach level 255 (GM) to access this menu.");
						objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back]", 99); // Goes to the main menu
						Menu->SendTo(Plr);
				}
				break;

			case 17: // GM Spells Menu 
				{
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
					Menu->AddItem(0, "Teach me Frost Breath", 20); // will teach frost breath
					Menu->AddItem(0, "More coming soon.. [Back to GM Menu]", 16); // will send back to the GM menu
					Menu->AddItem(0, "[Back To Main Menu]", 99); // Will go back to the main menu
					Menu->SendTo(Plr);
				}
				break;

			case 20: // Teaches Frost Breath
				{
					Plr->addSpell(28524); // This adds spell 28524 to the GM.. Frost Breath
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
					Menu->AddItem(0, "[Back to GM Menu]", 16); // Sends to GM menu
					Menu->AddItem(0, "[Back To Main Menu]", 99); // Sends to main menu
					Menu->SendTo(Plr);
				}
				break;

			case 18: // GM Teleports Menu
				{
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
					Menu->AddItem(0, "Old GM Island", 21); // This will teleport to the Old GM Island
					Menu->AddItem(0, "[Back to GM Menu]", 16); // sends to GM menu
					Menu->AddItem(0, "[Back To Main Menu]", 99); // sends to main menu
					Menu->SendTo(Plr);
				}
				break;

			case 21: // Old GM Island Port
				{
					Plr->SafeTeleport(1, 0, -11862.599609, -4577.041504, 0.448359, 0); // Teleports to the islands
					Plr->Gossip_Complete(); // closes menu
				}
				break;

			case 19://This is the GM Sets menu
				{
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
					Menu->AddItem(0, "Icecoldcoke Set", 22); // Adds Icecoldcoke's GM set to the GM
					Menu->AddItem(0, "[Back to GM Menu]", 16); // sends to GM menu
					Menu->AddItem(0, "[Back To Main Menu]", 99); // sends to main menu
					Menu->SendTo(Plr);
				}
				break;

			case 22: // Icecoldcoke's GM Set adding -- For now just adds turbo Charged flying machine (34061) .. since set IDs are wrong atm :P
				{
					pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "You now have Icecoldcoke's GM Set. (Note : Turbo Charged Flying Machine atm)"); // Message to be changed when set IDs corrected
						Item * pItem = objmgr.CreateItem(34061, Plr);
						Plr->GetItemInterface()->AddItemToFreeSlot(pItem); // Adds the item to a free slot
					objmgr.CreateGossipMenuForPlayer(&Menu, pCreature->GetGUID(), 1, Plr);
						Menu->AddItem(0, "[Back To Main Menu]", 99); // sends to main menu
						Menu->AddItem(0, "[Back to GM Menu]", 16); // sends to gm menu
						Menu->SendTo(Plr);
				}
				break;

			case 23: // Tries to fix the money, if they have more than 200k.
				{
					uint32 currentgold = Plr->GetUInt32Value(PLAYER_FIELD_COINAGE);
				if (currentgold>2000000000) // Checks if gold count is higher than 200k (Not equal to, because that wouldn't need fixing)
				{
					Plr->SetUInt32Value(PLAYER_FIELD_COINAGE,1500000000); // Sets gold to 150k
					Plr->BroadcastMessage("Your gold has been lowered to 150k.");
					Plr->Gossip_Complete();
				}
				else
				{
					Plr->BroadcastMessage("Your gold doesn't need fixing, you have less than 200k gold. If you happen to get over 200k later, come back to me");
					Plr->Gossip_Complete();
				}
				}
				break;
					


			case 99: //This is the main menu that the "back", and "back to main menu" uses.
				{
					objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
					Menu->AddItem(0, "So... thirsty...", 1); // Milk Menu
					Menu->AddItem(0, "Teleport Menu", 2); // Teleport Menu
					Menu->AddItem(0, "GM Menu (Req. Lvl 255)", 16); // GM Menu
					Menu->AddItem(10, "Please Morph me Back to Normal!", 15); // Demorph
					Menu->AddItem(0, "Please fix my gold, Icecoldcoke.", 23);
					Menu->SendTo(Plr);	
				}
				break;
	}
}
}
}
}

void Icecoldcoke::GossipEnd(Object * pObject, Player* Plr)
{
    GossipScript::GossipEnd(pObject, Plr);
}

void SetupIcecoldcoke(ScriptMgr * mgr)
{
    GossipScript * gs = (GossipScript*) new Icecoldcoke();
	mgr->register_gossip_script(690003, gs);
}